#include "TcpServer.h"

void onNewConnection(const TcpConnectionPtr &con){
    cout<<"建立连接，连接信息为："<<con->streamToString()<<endl;
}

void onMessage(const TcpConnectionPtr &con){
    cout<<"收到消息，连接信息为："<<con->streamToString()<<endl;
    string msg = con->receive();
    cout<<"消息内容："<<msg<<endl;
    con->send("hello handsome\n");
}

void onClose(const TcpConnectionPtr &con){
    cout<<"关闭连接，连接信息为："<<con->streamToString()<<endl;
}

int main(){
    // Acceptor acc("192.168.2.57",12345);
    // acc.ready();
    // EventLoop eloop(acc);
    // eloop.setNewConnectionCallback(onNewConnection);
    // eloop.setMessageCallback(onMessage);
    // eloop.setCloseCallback(onClose);
    // eloop.loop();
    TcpServer ts("192.168.2.57",12345);
    ts.setAllCallback(onNewConnection,onMessage,onClose);
    ts.start();
    return 0;
}